package org.file5.domain;

import org.compass.annotations.Searchable;
import org.compass.annotations.SearchableProperty;
import org.springframework.web.multipart.MultipartFile;

import com.google.appengine.api.datastore.Blob;
import com.googlecode.objectify.annotation.NotSaved;

@Searchable(alias = "Attachment")
public class Attachment extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1175172241881417378L;

	public Attachment() {
	}

 
	@SearchableProperty(name = "name")
	private String name;

 
	private String fileExt;


 
	private String fileType;

 
	private Blob fileContent;

	// used to store fileBytes from the HTML form
	@NotSaved
	private MultipartFile multipartFile;


	// -------------BaseEntity Fields------------


	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFileType() {
		return fileType;
	}

	public void setFileType(String fileType) {
		this.fileType = fileType;
	}

	public Blob getFileContent() {
		return fileContent;
	}

	public void setFileContent(Blob fileContent) {
		this.fileContent = fileContent;
	}


	public Attachment(byte[] fileContent) {
		this.fileContent = new Blob(fileContent);
	}

	public MultipartFile getMultipartFile() {
		return multipartFile;
	}

	public void setMultipartFile(MultipartFile multipartFile) {
		this.multipartFile = multipartFile;
	}

	public String getFileExt() {
		return fileExt;
	}

	public void setFileExt(String fileExt) {
		this.fileExt = fileExt;
	}

	public boolean isImage() {
		if (("image/gif".equals(fileType)) || ("image/png".equals(fileType))
				|| ("image/jpeg".equals(fileType))) {
			return true;
		}
		return false;
	}

}
